﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Threading;


namespace NSServer
{
    [ServiceContract(SessionMode = SessionMode.Required)]
    public interface IPemsService
    {
        [OperationContract(IsInitiating = true)]
        bool loginElbiralas(string user, string pwd);
        
        [OperationContract(IsTerminating = true)]
        bool stop();
    } 

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class PemsService : IPemsService
    {
        public PemsService()
        {
            Console.WriteLine("Service object created (ID):   " + this.GetHashCode().ToString());
        }

        ~PemsService()
        {
            Console.WriteLine("Service object destroyed (ID): " + this.GetHashCode().ToString());
        }

        /// <summary>
        /// egy felhasználó használhatja-e a rendszert?
        /// </summary>
        /// <param name="user">őt vizsgáljuk</param>
        /// /// <param name="user">ilyen jelszóval</param>
        /// <returns>visszaadjuk a belépési jogosultságot (igen/nem)</returns>
        public bool loginElbiralas(string user, string pwd)
        {
            bool ret = false;
            lock (Data.emberlist)
            {
                foreach (Ember e in Data.emberlist)
                {
                    if (e.userName == user && e.password == pwd)
                    {
                        ret = true;
                    }
                }
            }
            return ret;
        }

        public bool stop()
        {
            return true;
        } 
    } 


}
